//
//  BaseTabBarViewController.m
//  JYShop
//
//  Created by 花花 on 2017/9/28.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "BaseTabBarViewController.h"
#import "BaseUIViewController.h"
#import "BaseNavViewController.h"

@interface BaseTabBarViewController ()<UITabBarControllerDelegate>

@end

@implementation BaseTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupControllers];
}

- (void)setupControllers{
    //控制器的名字
    NSArray *ControllerViews = @[@"JYHomeController",@"JYListController",@"JYShopController",@"JYMineController"];
    //TabBar图片
    NSArray *normalImageNames = @[@"home_nav_home", @"home_nav_listing", @"home_nav_shopping_cart", @"home_nav_mine"];
    //TabBar选中的图片
    NSArray *selectImageNames = @[@"home_nav_home_click", @"home_nav_listing_click", @"home_nav_shopping_cart_click", @"home_nav_mine_click"];
    
    //TabBarItem标题
    NSArray *titles = @[@"首页",@"常用清单",@"购物车",@"我的"];
    
    
    for (int i = 0; i< ControllerViews.count; i++)
    {
        //1.获取类名字符串
        NSString *className= ControllerViews[i];
        //2。获取类名
        Class class = NSClassFromString(className);
        //3.创建对象
        BaseUIViewController * viewController  = [[class alloc] init];
        viewController.title = titles[i];
        self.tabBar.tintColor = kThemeColor;
        self.tabBar.translucent = NO;
        self.delegate = self;
        viewController.tabBarItem.image = [[UIImage imageNamed:normalImageNames[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        viewController.tabBarItem.selectedImage =  [[UIImage imageNamed:selectImageNames[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        BaseNavViewController *Nav = [[BaseNavViewController alloc]initWithRootViewController:viewController];
        Nav.navigationBar.translucent = NO;
        [self addChildViewController:Nav];
        
        //        if (i==0) viewController.hiddenNavBar = YES;
        
    }
    //默认选中第一个
    self.selectedIndex = 0;
    
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(BaseUIViewController *)viewController{

    NSLog(@"tabBar---%@",viewController.title);

}
@end
